home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Zoomed Video Driver v1.0 SDK / Tools / PC Card DispNameReg / Src / DisplayWindowManager.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-06-02  |  7.5 KB  |  295 lines  |  [TEXT/CWIE]

  1. /*                                DisplayWindowManager.c                            */
  2. /*
  3.  * Copyright © 1993-94 Apple Computer Inc. All rights reserved.
  4.  */
  5. #include "DisplayNameRegistry.h"
  6. #include "IntlResources.h"
  7. #include "Script.h"
  8. #include "TextUtils.h"
  9. #include "SegLoad.h"
  10. #include "FixMath.h"
  11. #include "ToolUtils.h"
  12. #include "Gestalt.h"
  13.  
  14. #define LIST    (**BROWSER.theList)
  15.  
  16.  
  17. /*
  18.  * MakeNameRegistryBrowserWindow
  19.  * Create a window, the twist-down list, and fill it with file names.
  20.  */
  21. OSErr
  22. MakeNameRegistryBrowserWindow(void)
  23. {
  24.         OSErr                    status;
  25.         register BrowserPtr        browserPtr;
  26.         WindowPtr                theWindow;
  27.         Rect                    viewRect;
  28.         long                    response;
  29.         Boolean                    hasColorQuickDraw;
  30.         long                    fontSize;
  31.         Str255                    work;
  32.  
  33.         status = noErr;
  34.         hasColorQuickDraw = FALSE;
  35.         if (Gestalt(gestaltQuickdrawVersion, &response) == noErr
  36.          && response >= gestalt8BitQD)
  37.              hasColorQuickDraw = TRUE;
  38.         viewRect = qd.screenBits.bounds;
  39.         InsetRect(&viewRect, 4, 4);
  40.         viewRect.top += (GetMBarHeight() * 2);
  41. #ifdef SYSF
  42.         viewRect.bottom = viewRect.top + 300;
  43.         viewRect.right = viewRect.left + 450;
  44. #endif        
  45.         //** To do: adjust the viewRect so the window starts off with an
  46.         //** integral number of text lines.
  47.         browserPtr = (BrowserPtr) NewPtrClear(sizeof (BrowserRecord));
  48.         if (browserPtr == NULL)
  49.             status = MemError();
  50.         if (status == noErr) {
  51.             if (hasColorQuickDraw) {
  52.                 theWindow = NewCWindow(
  53.                             (Ptr) browserPtr,        /* Our data storage            */
  54.                             &viewRect,                /* Screen bounds            */
  55.                             "\pName Registry",        /* Window title                */
  56.                             FALSE,                    /* Initially invisible        */
  57.                             zoomDocProc,            /* Normal document            */
  58.                             (WindowPtr) -1L,        /* Put in front                */
  59.                             TRUE,                    /* Has go away                */
  60.                             0                        /* No refCon                */
  61.                         );
  62.             }
  63.             else {
  64.                 theWindow = NewWindow(
  65.                             (Ptr) browserPtr,        /* Our data storage            */
  66.                             &viewRect,                /* Screen bounds            */
  67.                             "\pName Registry",        /* Window title                */
  68.                             FALSE,                    /* Initially invisible        */
  69.                             zoomDocProc,            /* Simple document            */
  70.                             (WindowPtr) -1L,        /* Put in front                */
  71.                             TRUE,                    /* Has go away                */
  72.                             0                        /* No refCon                */
  73.                         );
  74.             }
  75.             if (theWindow == NULL)
  76.                 status = memFullErr;
  77.         }
  78.         if (status == noErr) {
  79.             SetPort(theWindow);                        /* Do this first, or else    */
  80.             viewRect = theWindow->portRect;
  81.             viewRect.right -= (kScrollBarWidth - 1);
  82.             viewRect.bottom -= (kScrollBarWidth - 1);
  83.             GetIndString(BROWSER.fontNameText, STRN_Options, kOptionFontName);
  84.             GetIndString(work, STRN_Options, kOptionFontSize);
  85.             GetFNum(BROWSER.fontNameText, &BROWSER.fontNumber);
  86.             StringToNum(work, &fontSize);
  87.             BROWSER.fontSize = fontSize;
  88.             TextFont(BROWSER.fontNumber);
  89.             TextSize(BROWSER.fontSize);
  90.             BROWSER.theList = NewTwistDownList(
  91.                         &viewRect,                    /* Where it will be seen    */
  92.                         DisplayListDrawProc,        /* Our private drawing func    */
  93.                         CharWidth('n'),                /* Tab indentation amount    */
  94.                         FALSE,                        /* Hilite selections?        */
  95.                         (GetSysDirection() == 0),    /* Current system just.        */
  96.                         TRUE                        /* Has Grow Box                */
  97.                     );
  98.             if (BROWSER.theList == NULL)
  99.                 status = memFullErr;                    /* Oops                            */
  100.         }
  101.         if (status == noErr) {
  102.             gCurrentBrowserPtr = browserPtr;
  103.             BROWSER.sortByName = TRUE;
  104.             ShowWindow(theWindow);
  105.             SelectWindow(theWindow);
  106.             gUpdateMenusNeeded = TRUE;
  107.             ++gOpenWindowCount;
  108.             DoEnumerateNameRegistry(browserPtr);
  109.         }
  110.         return (status);
  111. }
  112.  
  113. void
  114. DoRefreshDisplay(
  115.         BrowserPtr                browserPtr
  116.     )
  117. {
  118.         InitializeDisplayList(browserPtr);
  119.         DisposeTwistDownHdl(REG.firstElement, NULL, NULL);
  120.         NewTwistDownSiblingSet(®);
  121.         LDelRow(0, 0, BROWSER.theList);
  122.         DoEnumerateNameRegistry(browserPtr);
  123. }
  124.  
  125. void
  126. DoEnumerateNameRegistry(
  127.         BrowserPtr                browserPtr
  128.     )
  129. {
  130.         Ptr                        privateStash;
  131.         Str255                    work;
  132.  
  133.         SetCursor(*GetCursor(watchCursor));
  134.         /*
  135.          * Because the enumerator can absorb all available memory, we grab a chunk
  136.          * of memory that we restore before building and displaying the visible.
  137.          * list. This isn't a really great solution, but it will do for now.
  138.          */
  139.         privateStash = NewPtr(32768L);
  140.         if (privateStash != NULL) {
  141.             EnumerateNameRegistry(browserPtr);
  142.             DisposePtr(privateStash);
  143.         }
  144.         /*
  145.          * The registry has been enumerated and the list of names, properties,
  146.          * and values constructed. Display the number of things found in the
  147.          * Window title and display the initial list.
  148.          */
  149.         NumToString(CountListElements(REG.firstElement), work);
  150.         pstrcat(work, "\p - total names, properties, and values found");
  151.         SetWTitle((WindowPtr) &BROWSER.theWindow, work);
  152.         SortAndDisplayBrowserWindow(browserPtr);
  153. }
  154.  
  155. /*
  156.  * DisposeBrowser
  157.  * The user clicked on the closer. Dispose of the window and its contents.
  158.  */
  159. void
  160. DisposeBrowser(
  161.         register BrowserPtr        browserPtr
  162.     )
  163. {
  164.         InitializeDisplayList(browserPtr);
  165.         DisposeTwistDownList(BROWSER.theList);
  166.         DisposeTwistDownHdl(REG.firstElement, NULL, 0);
  167.         CloseWindow((WindowPtr) &BROWSER.theWindow);
  168.         DisposePtr((Ptr) browserPtr);
  169.         gUpdateMenusNeeded = TRUE;
  170.         --gOpenWindowCount;
  171. }
  172.  
  173. /*
  174.  * ActivateBrowser
  175.  * This is called on activate and deactivate (or suspend/resume) events to enable
  176.  * or disable the window content.
  177.  */
  178. void
  179. ActivateBrowser(
  180.         register BrowserPtr        browserPtr,
  181.         Boolean                    activating
  182.     )
  183. {
  184.         LActivate(activating, BROWSER.theList);
  185. }
  186.  
  187. /*
  188.  * DoWindowKeyDown
  189.  */
  190. void
  191. DoWindowKeyDown(
  192.         register BrowserPtr        browserPtr
  193.     )
  194. {
  195.         UNUSED(browserPtr);
  196.         /* Nothing happens here */
  197. }
  198.  
  199. /*
  200.  * DoContentClick
  201.  * Click in the window. This function decides which element received the click and
  202.  * calls the requisite click handler. In this example, we need only deal with
  203.  * the twist-down list.
  204.  */
  205. void
  206. DoContentClick(
  207.         register BrowserPtr        browserPtr,
  208.         const EventRecord        *eventRecordPtr
  209.     )
  210. {
  211.         Cell                    theCell;
  212.         TwistDownClickState        clickState;
  213.         
  214.         clickState = DoTwistDownClick(BROWSER.theList, eventRecordPtr, &theCell);
  215.         switch (clickState) {
  216.         case kTwistDownNotInList:            /* Not in list view rectangle        */
  217.         case kTwistDownNoClick:                /* Scroll bar or user changed mind    */
  218.             break;                            /* Ignore this click                */
  219.         case kTwistDownButtonClick:            /* Clicked on expansion button        */
  220.             break;                            /* Done for us                        */
  221.         case kTwistDownClick:                /* Single-click on list datum        */
  222.         case kTwistDownDoubleClick:            /* Double-click on list datum        */
  223.             break;                            /* Ignore these clicks                */
  224.         }
  225. }
  226.  
  227. /*
  228.  * UpdateBrowserWinow
  229.  * Process an update event in this window.
  230.  */
  231. void
  232. UpdateBrowserWindow(
  233.         register BrowserPtr        browserPtr,
  234.         RgnHandle                updateRgn
  235.     )
  236. {
  237.         Rect                    viewRect;
  238.         
  239.         viewRect = (**(BROWSER.theList)).rView;
  240.         InsetRect(&viewRect, -1, -1);
  241.         FrameRect(&viewRect);
  242.         LUpdate(updateRgn, BROWSER.theList);
  243. }
  244.  
  245. void
  246. DecorateBrowserWindow(
  247.         register BrowserPtr        browserPtr
  248.     )
  249. {
  250.         Rect                    listRect;
  251.  
  252.         listRect = ((WindowPtr) &BROWSER.theWindow)->portRect;
  253.         listRect.bottom -= kScrollBarWidth;
  254.         listRect.right -= kScrollBarWidth;
  255.         SizeTwistDownList(
  256.             BROWSER.theList,
  257.             width(listRect),
  258.             height(listRect)
  259.         );
  260. }
  261.  
  262. void
  263. PrintBrowserWindow(
  264.         register BrowserPtr        browserPtr
  265.     )
  266. {
  267.         OSErr                    status;
  268.         
  269.         status = PrintTwistDownList(
  270.             BROWSER.theList,
  271.             &gPrintHandle,
  272.             FALSE,
  273.             NULL,                        /* No setup callback function    */
  274.             //** DisplayListPrintImageProc,    /* Our print page function        */
  275.             NULL,                        /* Use default print image proc    */
  276.             NULL,                        /* No exit callback function    */
  277.             browserPtr                    /* Refcon - for font info        */
  278.         );
  279.         if (status != noErr)
  280.             NonFatalError(status, "\pPrinting failed");
  281. }
  282.  
  283. void
  284. DoSetFontInfo(
  285.         register BrowserPtr        browserPtr
  286.     )
  287. {
  288.         SetTwistDownListFont(
  289.             BROWSER.theList,
  290.             BROWSER.fontNumber,
  291.             BROWSER.fontSize
  292.         );
  293. }
  294.  
  295.